<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />

<div class="t_bar">基地基本信息</div>
<table class="t_css" width="100%" id="table_01">
    <col style="width: 20%;" />
    <col style="width: 30%;" />
    <col style="width: 20%;" />
    <col style="width: 30%;" />

    <tr>
        <td align="right"><span class="color_red">*</span>创新基地名称：</td>
        <td>
            <input type='text' name='proposal/zh_title' id='zh_title' style="width: 92%"
                   class="input_css required" maxlength="50"
                   value='<x:out select="$xmlData/data/proposal/zh_title"/>' label="创新基地名称">
        </td>
        <td align="right"><span class="color_red">*</span>研究领域：</td>
        <td>
            <input type="text" label="研究领域" name="proposal/field_or_subject"
                   class="input_css required" maxlength="50"
                   value="<x:out select="$xmlData/data/proposal/field_or_subject" />">
        </td>
    </tr>
    <tr>
        <td align="right"><span class="color_red">*</span>填报日期：</td>
        <td>
            <c:set var="submit_date">
                <x:out select="$xmlData/data/proposal/submit_date" />
            </c:set>
            <cpt:date id="apply_date_curr" name="proposal/submit_date" value="${submit_date}"
                      className="required date" label="填报日期"></cpt:date>
        </td>
        <td align="right"><span class="color_red">*</span>归口管理部门：</td>
        <td>
            <c:set var="recomend_org">
                {'id':'<x:out select="$xmlData/data/proposal/recomend_org_value" />',
                'name':'<x:out select="$xmlData/data/proposal/recomend_org_name" />'
                }
            </c:set> <cpt:tree id="recomend_org" key="recommended_org" cacheable="false" className="hn_iuput_kuang required selectWidth3" readonly="true"  value="${recomend_org}" label="归口管理部门"
                               showPattern="all" shieldPattern="0" onClick="initTreeValueExt">
        </cpt:tree>
            <input type="hidden" id="recomend_org_value" name="proposal/recomend_org_value"  value="<x:out select="$xmlData/data/proposal/recomend_org_value" />" >
            <input type="hidden" name="proposal/recomend_org_name" value="<x:out select="$xmlData/data/proposal/recomend_org_name" />">
        </td>
    </tr>

    <tr>
        <td align="right">负责人：</td>
        <td>
            <span name="proposal/fzr_psnname"><x:out select="$xmlData/data/zh_persons/zh_person[@submit_psn='1']/basic_info/zh_name"/></span>
        </td>
        <td align="right" nowrap>依托单位：</td>
        <td >
            <span name="organizations/organization[0]/org_name"><x:out select="$xmlData/data/organizations/organization[@submit_org='1']/org_name" /></span>
        </td>
    </tr>
    <tr>
        <td align="right" >通讯地址：</td>
        <td colspan="3">
            <span name="organizations/organization[0]/address"><x:out select="$xmlData/data/organizations/organization[@submit_org=1]/address" /></span>
        </td>
    </tr>
    <tr>
        <td align="right"><span class="color_red">*</span>联系人姓名：</td>
        <td >
            <input type="text" label="联系人姓名" name="proposal/contact_psn_cname"
                   class="input_css required" maxlength="50"
                   value="<x:out select="$xmlData/data/proposal/contact_psn_cname" />">
        </td>
        <td align="right"><span class="color_red">*</span>手机：</td>
        <td>
            <input type="text" label="手机" name="proposal/contact_psn_mobile"
                   class="input_css required mobile" onfocus="InitInput.setNumber(this,11,0,0)"
                   maxlength="11"
                   value="<x:out select="$xmlData/data/proposal/contact_psn_mobile" />">
        </td>
    </tr>
    <tr>
        <td align="right"><span class="color_red">*</span>邮政编码：</td>
        <td>
            <input type="text" label="邮政编码" name="proposal/contact_psn_postal_code" class=" required" maxlength="6"
                   onkeyup="this.value=this.value.replace(/\D/g,'')"  onafterpaste="this.value=this.value.replace(/\D/g,'')"
                   value="<x:out select="$xmlData/data/proposal/contact_psn_postal_code" />">
        </td>
        <td align="right"><span class="color_red">*</span>邮箱：</td>
        <td >
            <input type="text" label="邮箱" name="proposal/contact_psn_email"
                   class="input_css required email" maxlength="30"
                   value="<x:out select="$xmlData/data/proposal/contact_psn_email" />">
        </td>
    </tr>
</table>
<div class="t_bar">共建单位</div>
<table  id="heisi_wangkun" cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;table-layout: fixed;" >
    <col width="7%" />
    <col width="8%" />
    <col width="85%" />
    <thead >
    <tr style="border:1px solid #B7D1E6">
        <th class="TblHead" align="center" >选择</th>
        <th class="TblHead" align="center" >序号</th>
        <th class="TblHead" align="center" >单位名称</th>
    </tr>
    </thead>
    <tbody id="tab">
    <tr style="display:none" align="center">
        <td align="center">
            <input type="radio" class="radiobutton" name="heisi_wangkun" >
        </td>
        <td align="center">
            <span name="heisi_wangkun|list[0]@seq_no" >[index]</span>
        </td>
        <td align="center">
            <input type="text" name="heisi_wangkun|list[0]|content" label="单位名称" class=" required input_text " maxlength="50" style="width:80%"/>
        </td>
    </tr>

    <c:set value="0" var="index" scope="page"/>
    <x:forEach select="$xmlData/data/heisi_wangkun/list" var="list">

        <c:choose>
            <c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
            <c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
        </c:choose>
        <tr align="center">
            <td align="center">
                <input type="radio" class="radiobutton" name="heisi_wangkun" >
            </td>
            <td align="center">
                <span name="heisi_wangkun/list[${flag}${index}]@seq_no" ><x:out select="$list/@seq_no"/></span>
            </td>
            <td align="center">
                <input type="text" name="heisi_wangkun/list[${flag}${index}]/content"  value="<x:out select="$list/content"/>"   label="单位名称" class=" required input_text " maxlength="50" style="width:80%"/>
            </td>
        </tr>
        <c:set value="${index+1}" var="index" scope="page"/>
    </x:forEach>
    <script type="text/javascript">
        showAllDateTag("heisi_wangkun");
    </script>
    </tbody>
</table>
<table width="98%" align="center" border="0">
    <tr style="border: 0"><td style="border: 0">
        <input class="button" name="cmdAddbefore" type=button value="添加" onclick="if(checkTabLimit('heisi_wangkun',5,'共建单位最多只能添加5条')){addNewRow('heisi_wangkun');showDateTag('heisi_wangkun');try{top.resizeFrame();}catch(e){};}">
        <input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev3('heisi_wangkun','heisi_wangkun')">
        <input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext3('heisi_wangkun','heisi_wangkun')">
        <input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow3('heisi_wangkun','共建单位');">
    </td></tr>
</table>

<script type="text/javascript">

    /**
     * 上移行
     * @param tblId
     * @returns {Boolean}
     */
    function movePrev3(tblId,selName) {
        if (!selName)
            selName = "";
        if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
            scmWarn(irisNotes.prevWarn);
            return false;
        }
        if ($("#" + tblId + " tr").length <= 2)
            return false;
        var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
            .parents("tr").first();// 取得被选中的行
        var trPrev = trChecked.prev();// 取得上一行
        var index = trChecked.get(0).rowIndex;// 获得行号
        if (index <= 2) {// 如果是第一行
            scmWarn(irisNotes.tabelMoveWarn1);
            return false;
        }
        //trChecked.remove();
        trPrev.before(trChecked);
        trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
        refreshRowINdex33(tblId);
    }

    /**
     * 下移行
     * @param tblId
     * @returns {Boolean}
     */
    function moveNext3(tblId,selName) {
        if (!selName)
            selName = "";
        if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
            scmWarn(irisNotes.nextWarn);
            return false;
        }
        if ($("#" + tblId + " tr").length <= 2) {
            return false;
        }
        var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
            .parents("tr").first();// 取得被选中的行
        var trNext = trChecked.next();
        var index = trChecked.get(0).rowIndex;// 获得行号
        if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
            scmWarn(irisNotes.tabelMoveWarn2);
            return false;
        }
        //trChecked.remove();
        trNext.after(trChecked);
        trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
        refreshRowINdex33(tblId);
    }

    /**
     * 重新计算行号
     * @param tblId
     */
    function refreshRowINdex33(tblId){
        //重新计算行号
        $("#"+tblId+" tr").each(function(){
                var seq=$(this).get(0).rowIndex;//获得行数
                if(seq>1){//如果有行  显示时display行不计入类，故只减1
                    seq=seq-1;
                    var seq_no=$(this).find("[name$='seq_no']");
                    if(seq_no.is("span"))
                        seq_no.html(seq);
                    else
                        seq_no.val(seq);

                    seq=""+(seq-1);
                    if(seq.length==1)
                        seq="0"+seq;
                    //替换相应的name参数的seq
                    $(this).find("input,span,textarea,select").each(function(){
                        var name=$(this).attr("name");
                        if(name!=null&&name!=""){
                            name=name.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("name",name);
                        }
                        var id=$(this).attr("id");
                        if(id!=null&&id!=""){
                            id=id.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("id",id);
                            id=id.replace(/\d+/g,""+seq+"");
                            $(this).attr("id",id);
                        }
                        var className=$(this).attr("class");
                        if(className!=null&&className!=""){
                            className=className.replace(/\[\d*\]/g,"["+seq+"]");
                            $(this).attr("class",className);
                        }
                    });
                }
            }
        );

    }


    /**
     * 删除一行
     * @param radioId
     */
    function deleteSelectedRow3(tableId,message,nummin,warnMsg,selName){
        if(!selName)selName="";
        var tr=$("#"+tableId+" :radio[name*='"+selName+"']:checked").parents("tr");
        if(nummin==null)
            nummin=0;
        var length=tr.length;
        if(tr.length==0)
            tr=$("#"+tableId+" tr").filter(":last");
        else if(tr.length>1)
            tr=tr.first();

        if(tr.get(0).rowIndex-1==nummin){
            scmWarn(irisNotes.delWarn1);
            return false;
        }
        if(length==0){

            scmWarn(irisNotes.delWarn2);

            return false;
        }
        if(!confirm(messageTip.deleteTip+message+"？"))
            return false;
        tr.remove();
        refreshRowINdex33(tableId);
        return true;
        setSubmitOrg() ;
    }
    //下拉选择赋值
    function initTreeValueExt(treeId, treeNode) {
        if ((treeNode && treeNode.isParent)) {
            scmWarn("请选择具体的" + $("#" + treeId).attr("label"));
            $("#" + treeId).val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId	+ "_value']").val("");
            $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val("");
            return false;
        }
        var str = treeNode.name;
        var obj = treeNode.parentNode;
        while (obj != null) {
            str = obj.name + "-" + str;
            obj = obj.parentNode;
        }

        $("#" + treeId).parents("td").find("[name$='" + treeId + "_code'],[id$='" + treeId + "_code']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_value'],[id$='" + treeId + "_value']").val(treeNode.id);
        $("#" + treeId).parents("td").find("[name$='" + treeId + "_name'],[id$='" + treeId + "_name']").val(str);
    }
</script>

